<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>common.js</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            common.js
        </h1>
        <ul class="files">
            
            <li>
                lib/assets/javascripts/common.js
                
            </li>
            <li>Last modified: 2017-02-24 15:07:24 +0800</li>
        </ul>
    </div>

    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>// 通用事件 var commonEvents = {</p>

<pre><code>// 设置事件
setOrdinaryEvents: function () {
    if (document.getElementById(&quot;back&quot;)) {
        document.getElementById(&quot;back&quot;).onclick = function () {
            history.go(-1)
        }
    }
},
popupView: function(headerStr, bodyStr) {
    var modalObj = document.getElementById(&quot;myModal&quot;)
    commonEvents.openPopupView(headerStr, bodyStr, modalObj)
    $(&#39;#myModal&#39;).ready(function () {
        var popup_h = $(this).find(&quot;.modal-content&quot;).height() + 2
        var enable_win_h = $(window).height()
        if (popup_h &lt; enable_win_h) {
            var margin_top = (enable_win_h - popup_h) * 0.5
            $(&quot;#myModal .modal-dialog&quot;).css(&quot;margin-top&quot;,margin_top)
        } else {
            $(&quot;#myModal .modal-dialog&quot;).css(&quot;margin-top&quot;,0)
        }
        $(document).on(&quot;click&quot;,&quot;#myModal #modal_okBtn&quot;,function () {
            commonEvents.ok()
            commonEvents.closePopupView(modalObj)
            commonEvents.okCallBack()
        })
        $(&quot;#myModal #modal_cancelBtn&quot;).on(&quot;click&quot;,function (event) {
            commonEvents.closePopupView(modalObj);
        })
        $(&quot;#myModal #modal_closeBtn&quot;).on(&quot;click&quot;,function () {
            commonEvents.closePopupView(modalObj);
        })
    })
},
openPopupView: function(headerStr, bodyStr, modalObj) {
    $(&quot;#myModal .modal-header #modalLabel&quot;).html(headerStr)
    $(&quot;#myModal .modal-body&quot;).html(bodyStr)
    $(&quot;#myModal&quot;).after(&quot;&lt;div class=&#39;modal-backdrop fade in&#39;&gt;&lt;/div&gt;&quot;)
    $(&quot;#myModal&quot;).addClass(&quot;in&quot;)
    modalObj.setAttribute(&quot;aria-hidden&quot;,&quot;false&quot;)
    $(&#39;#myModal&#39;).show()
},
closePopupView: function(modalObj) {
    $(&quot;#myModal&quot;).removeClass(&quot;in&quot;)
    setTimeout(function () {
        $(&#39;#myModal&#39;).hide()
        $(&quot;#myModal .modal-header #modalLabel&quot;).html(&quot;&quot;)
        $(&quot;#myModal .modal-body&quot;).html(&quot;&quot;)
        modalObj.setAttribute(&quot;aria-hidden&quot;,&quot;true&quot;)
        $(&quot;.modal-backdrop&quot;).remove()
    },500)

},
validateCompleteness: function () {
    var not_null_objs = $(&quot;.not-null&quot;)
    var n = 0
    not_null_objs.each(function () {
        if (trim($(this).val()) == &quot;&quot;) n++
    })
    if (n == 0) {
        return true
    }
    return false
},
validateString: function (typeObj,value) {
    var phone_reg = /^1[34578]\d{9}$/
    var psw_reg = /^[^\s]{6,20}$/

    if (typeObj.toLowerCase().indexOf(&quot;phone&quot;) &gt;= 0 ) {
        if (phone_reg.test(value)) {
            return true
        }
        return false
    } else if (typeObj.toLowerCase().indexOf(&quot;password&quot;) &gt;= 0 || typeObj.toLowerCase().indexOf(&quot;psd&quot;) &gt;= 0) {
        if (psw_reg.test(value)) {
            return true
        }
        return false
    }
},
ok: function () {
},
okCallBack: function () {
    commonEvents.ok = function(){
    }
}</code></pre>

<p>} // 获取当前页面的名字标识 function getPageName() {</p>

<pre><code>if ($(&quot;#app-container&quot;).length &gt; 0 ) {
    return $(&quot;#app-container&quot;).attr(&quot;myApp&quot;)
}</code></pre>

<p>} function getPageView() {</p>

<pre><code>if ($(&quot;#app-container&quot;).length &gt; 0 ) {
    return $(&quot;#app-container&quot;).attr(&quot;myView&quot;)
}</code></pre>

<p>}</p>

<p>function showErrorView(alertText) {</p>

<pre><code>var popup_error;
if (alertText == &quot;&quot; || alertText == null) {
    popup_error = &quot;&lt;div class=&#39;POPUP-ERROR&#39;&gt;没有获取到数据&lt;/div&gt;&quot;
} else {
    popup_error = &quot;&lt;div class=&#39;POPUP-ERROR&#39;&gt;&quot; + alertText + &quot;&lt;/div&gt;&quot;;
}
$(&quot;body&quot;).append(popup_error);
var winHeight = $(window).height();
var popHeight = $(&quot;.POPUP-ERROR&quot;).height();
var heightPosition = (winHeight - popHeight) / 2;
$(&quot;.POPUP-ERROR&quot;).css(&quot;top&quot;,heightPosition);

$(&quot;.POPUP-ERROR&quot;).fadeIn(2000,function() {
    $(&quot;.POPUP-ERROR&quot;).fadeOut(2000);
    setTimeout(function() {
        $(&quot;.POPUP-ERROR&quot;).remove();
    },2000);
});</code></pre>

<p>}</p>

<p>function setDateTimePicker() {</p>

<pre><code>$.fn.datetimepicker.dates[&#39;zh-CN&#39;] = {
    days: [&quot;星期日&quot;, &quot;星期一&quot;, &quot;星期二&quot;, &quot;星期三&quot;, &quot;星期四&quot;, &quot;星期五&quot;, &quot;星期六&quot;],
    daysShort: [&quot;周日&quot;, &quot;周一&quot;, &quot;周二&quot;, &quot;周三&quot;, &quot;周四&quot;, &quot;周五&quot;, &quot;周六&quot;],
    daysMin:  [&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;],
    months: [&quot;一月&quot;, &quot;二月&quot;, &quot;三月&quot;, &quot;四月&quot;, &quot;五月&quot;, &quot;六月&quot;, &quot;七月&quot;, &quot;八月&quot;, &quot;九月&quot;, &quot;十月&quot;, &quot;十一月&quot;, &quot;十二月&quot;],
    monthsShort: [&quot;1月&quot;, &quot;2月&quot;, &quot;3月&quot;, &quot;4月&quot;, &quot;5月&quot;, &quot;6月&quot;, &quot;7月&quot;, &quot;8月&quot;, &quot;9月&quot;, &quot;10月&quot;, &quot;11月&quot;, &quot;12月&quot;],
    meridiem: &quot;&quot;,
    today: &quot;今天&quot;,
    clear: &quot;清除&quot;
    //format: &quot;yyyy年mm月dd日&quot;,
    //titleFormat: &quot;yyyy年mm月&quot;,
    //weekStart: 1
};
$(&#39;.dateTimePicker&#39;).datetimepicker({
    language: &#39;zh-CN&#39;,          // 语言
    format: &#39;yyyy-mm-dd&#39;,       // 日期格式
    weekStart: 1,               // 周一
    todayBtn:  true,            // 是否显示今日按钮
    autoclose: true,            // 选择一个日期后自动关闭时间选择器
    todayHighlight: true,       // 今天高亮显示
    startView: 2,               // 0 hour, 1 day, 2 month, 3 year, 4 10year
    minView: 2,                 // 所能提供的最精准的时间选择视图 0:hour, 1:day, 2:month, 3:year, 4:10 year
    //maxView: 1,               // 所能提供的最高的选额范围视图 4:10year(默认)
    forceParse: true,           // 是否强制解析输入框中的值
    keyboardNavigation: true,   // 是否允许通过方向键改变日期
    pickerPosition: &quot;bottom-right&quot;
});</code></pre>

<p>}</p>

<p>function setDateTimePicker_new() {</p>

<pre><code>$.fn.datetimepicker.dates[&#39;zh-CN&#39;] = {
    days: [&quot;星期日&quot;, &quot;星期一&quot;, &quot;星期二&quot;, &quot;星期三&quot;, &quot;星期四&quot;, &quot;星期五&quot;, &quot;星期六&quot;],
    daysShort: [&quot;周日&quot;, &quot;周一&quot;, &quot;周二&quot;, &quot;周三&quot;, &quot;周四&quot;, &quot;周五&quot;, &quot;周六&quot;],
    daysMin:  [&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;],
    months: [&quot;一月&quot;, &quot;二月&quot;, &quot;三月&quot;, &quot;四月&quot;, &quot;五月&quot;, &quot;六月&quot;, &quot;七月&quot;, &quot;八月&quot;, &quot;九月&quot;, &quot;十月&quot;, &quot;十一月&quot;, &quot;十二月&quot;],
    monthsShort: [&quot;1月&quot;, &quot;2月&quot;, &quot;3月&quot;, &quot;4月&quot;, &quot;5月&quot;, &quot;6月&quot;, &quot;7月&quot;, &quot;8月&quot;, &quot;9月&quot;, &quot;10月&quot;, &quot;11月&quot;, &quot;12月&quot;],
    meridiem: &quot;&quot;,
    today: &quot;今天&quot;,
    clear: &quot;清除&quot;
    //format: &quot;yyyy年mm月dd日&quot;,
    //titleFormat: &quot;yyyy年mm月&quot;,
    //weekStart: 1
};
$(&#39;.dateTimePickerAll&#39;).datetimepicker({
    language: &#39;zh-CN&#39;,          // 语言
    format: &#39;yyyy-mm-dd hh:ii:ss&#39;,       // 日期格式
    weekStart: 1,               // 周一
    todayBtn:  true,            // 是否显示今日按钮
    autoclose: true,            // 选择一个日期后自动关闭时间选择器
    todayHighlight: true,       // 今天高亮显示
    startView: 2,               // 0 hour, 1 day, 2 month, 3 year, 4 10year
    // minView: 2,                 // 所能提供的最精准的时间选择视图 0:hour, 1:day, 2:month, 3:year, 4:10 year
    //maxView: 1,               // 所能提供的最高的选额范围视图 4:10year(默认)
    forceParse: true,           // 是否强制解析输入框中的值
    keyboardNavigation: true,   // 是否允许通过方向键改变日期
    pickerPosition: &quot;bottom-right&quot;
});</code></pre>

<p>}</p>

<p>function setTimePicker() {</p>

<pre><code>$.fn.datetimepicker.dates[&#39;zh-CN&#39;] = {
    days: [&quot;星期日&quot;, &quot;星期一&quot;, &quot;星期二&quot;, &quot;星期三&quot;, &quot;星期四&quot;, &quot;星期五&quot;, &quot;星期六&quot;],
    daysShort: [&quot;周日&quot;, &quot;周一&quot;, &quot;周二&quot;, &quot;周三&quot;, &quot;周四&quot;, &quot;周五&quot;, &quot;周六&quot;],
    daysMin:  [&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;],
    months: [&quot;一月&quot;, &quot;二月&quot;, &quot;三月&quot;, &quot;四月&quot;, &quot;五月&quot;, &quot;六月&quot;, &quot;七月&quot;, &quot;八月&quot;, &quot;九月&quot;, &quot;十月&quot;, &quot;十一月&quot;, &quot;十二月&quot;],
    monthsShort: [&quot;1月&quot;, &quot;2月&quot;, &quot;3月&quot;, &quot;4月&quot;, &quot;5月&quot;, &quot;6月&quot;, &quot;7月&quot;, &quot;8月&quot;, &quot;9月&quot;, &quot;10月&quot;, &quot;11月&quot;, &quot;12月&quot;],
    meridiem: &quot;&quot;,
    today: &quot;今天&quot;,
    clear: &quot;清除&quot;
    //format: &quot;yyyy年mm月dd日&quot;,
    //titleFormat: &quot;yyyy年mm月&quot;,
    //weekStart: 1
};
 $(&#39;.form_datetime&#39;).datetimepicker({
    language: &#39;zh-CN&#39;,          // 语言
    format: &#39;hh:ii&#39;,       // 日期格式
    weekStart: 1,               // 周一
    todayBtn:  true,            // 是否显示今日按钮
    autoclose: true,            // 选择一个日期后自动关闭时间选择器
    todayHighlight: true,       // 今天高亮显示
    startView: 1,               // 0 hour, 1 day, 2 month, 3 year, 4 10year
    minView: 0,                 // 所能提供的最精准的时间选择视图 0:hour, 1:day, 2:month, 3:year, 4:10 year
    //maxView: 1,               // 所能提供的最高的选额范围视图 4:10year(默认)
    forceParse: true,           // 是否强制解析输入框中的值
    keyboardNavigation: true,   // 是否允许通过方向键改变日期
    pickerPosition: &quot;bottom-right&quot;
});</code></pre>

<p>}</p>

<p>function setDatePicker() {</p>

<pre><code>$.fn.datetimepicker.dates[&#39;zh-CN&#39;] = {
    days: [&quot;星期日&quot;, &quot;星期一&quot;, &quot;星期二&quot;, &quot;星期三&quot;, &quot;星期四&quot;, &quot;星期五&quot;, &quot;星期六&quot;],
    daysShort: [&quot;周日&quot;, &quot;周一&quot;, &quot;周二&quot;, &quot;周三&quot;, &quot;周四&quot;, &quot;周五&quot;, &quot;周六&quot;],
    daysMin:  [&quot;日&quot;, &quot;一&quot;, &quot;二&quot;, &quot;三&quot;, &quot;四&quot;, &quot;五&quot;, &quot;六&quot;],
    months: [&quot;一月&quot;, &quot;二月&quot;, &quot;三月&quot;, &quot;四月&quot;, &quot;五月&quot;, &quot;六月&quot;, &quot;七月&quot;, &quot;八月&quot;, &quot;九月&quot;, &quot;十月&quot;, &quot;十一月&quot;, &quot;十二月&quot;],
    monthsShort: [&quot;1月&quot;, &quot;2月&quot;, &quot;3月&quot;, &quot;4月&quot;, &quot;5月&quot;, &quot;6月&quot;, &quot;7月&quot;, &quot;8月&quot;, &quot;9月&quot;, &quot;10月&quot;, &quot;11月&quot;, &quot;12月&quot;],
    meridiem: &quot;&quot;,
    today: &quot;今天&quot;,
    clear: &quot;清除&quot;
    //format: &quot;yyyy年mm月dd日&quot;,
    //titleFormat: &quot;yyyy年mm月&quot;,
    //weekStart: 1
};
$(&#39;.datePicker&#39;).datetimepicker({
    language: &#39;zh-CN&#39;,          // 语言
    format: &#39;yyyy-mm&#39;,       // 日期格式
    weekStart: 1,               // 周一
    todayBtn:  true,            // 是否显示今日按钮
    autoclose: true,            // 选择一个日期后自动关闭时间选择器
    todayHighlight: true,       // 今天高亮显示
    startView: 3,               // 0 hour, 1 day, 2 month, 3 year, 4 10year
    minView: 3,                 // 所能提供的最精准的时间选择视图 0:hour, 1:day, 2:month, 3:year, 4:10 year
    //maxView: 1,               // 所能提供的最高的选额范围视图 4:10year(默认)
    forceParse: true,           // 是否强制解析输入框中的值
    keyboardNavigation: true,   // 是否允许通过方向键改变日期
    pickerPosition: &quot;bottom-right&quot;
});</code></pre>

<p>}</p>

<p>// 求某一天指定天数前的日期 日期格式为 YYYY-MM-DD function
getDateBeforeSeveralDays(someDate,n) {</p>

<pre><code>var OneMonth = someDate.substring(5,someDate.lastIndexOf (&#39;-&#39;))
var OneDay = someDate.substring(someDate.length,someDate.lastIndexOf (&#39;-&#39;)+1)
var OneYear = someDate.substring(0,someDate.indexOf (&#39;-&#39;))
var mtime = (Date.parse(OneMonth+&#39;/&#39;+OneDay+&#39;/&#39;+OneYear) - n*24*60*60*1000)
var newTime = new Date(mtime)
var newYear = newTime.getFullYear()
var newMonth = (newTime.getMonth() + 1) == 13? 1 : newTime.getMonth() + 1
var newDay = newTime.getDate()
return newYear + &quot;-&quot; + setTwoDigit(newMonth) + &quot;-&quot; + setTwoDigit(newDay)</code></pre>

<p>}</p>

<p>// 获取今天的年月日 function getDateToday() {</p>

<pre><code>var date = new Date()
var year  = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var yearStr  = year
var monthStr = setTwoDigit(month)
var dayStr   = setTwoDigit(day)
return yearStr + &quot;-&quot; + monthStr + &quot;-&quot; + dayStr</code></pre>

<p>}</p>

<p>// 求某一天指定天数后的日期 日期格式为 YYYY-MM-DD function
getDateAfterSeveralDays(someDate,n) {</p>

<pre><code>var OneMonth = someDate.substring(5,someDate.lastIndexOf (&#39;-&#39;))
var OneDay = someDate.substring(someDate.length,someDate.lastIndexOf (&#39;-&#39;)+1)
var OneYear = someDate.substring(0,someDate.indexOf (&#39;-&#39;))
var mtime = (Date.parse(OneMonth+&#39;/&#39;+OneDay+&#39;/&#39;+OneYear) + n*24*60*60*1000)
var newTime = new Date(mtime)
var newYear = newTime.getFullYear()
var newMonth = (newTime.getMonth() + 1) == 13? 1 : newTime.getMonth() + 1
var newDay = newTime.getDate()
return newYear + &quot;-&quot; + setTwoDigit(newMonth) + &quot;-&quot; + setTwoDigit(newDay);</code></pre>

<p>}</p>

<p>// 设置为两位数数字 function setTwoDigit(n) {</p>

<pre><code>var str = &quot;0&quot;
if (n &lt; 10) {
    str += n
} else {
    str = n
}
return str</code></pre>

<p>}</p>

    </div>
  


  


  
  


  


  

  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>
